package com.zxc.service.impl;

import com.zxc.dao.CourseDao;
import com.zxc.dao.ExamDao;
import com.zxc.model.Exam;
import com.zxc.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    ExamDao examDao;
    @Autowired
    CourseDao courseDao;

    @Transactional
    @Override
    public void inserExam(Exam exam) {
        int flag = examDao.insertExam(exam);
        if (flag == 1) {
            courseDao.updateIsExam(exam.getClassid());
        }
    }

    @Override
    public Exam selectExamByClassId(Integer classId) {
        return examDao.selectByClassId(classId);
    }

    @Override
    public List<Exam> selectExamByStuId(Integer stuId) {
        return examDao.selectByStuId(stuId);
    }
}
